package info.motteke.mybws.impl;

import info.motteke.mybws.MyBws;
import info.motteke.mybws.Node;
import info.motteke.mybws.poi.WorkBookType;
import info.motteke.mybws.poi.WriteVisitor;
import info.motteke.mybws.script.ValueStack;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.poi.ss.usermodel.Workbook;

public class MyBwsImpl implements MyBws {

    private final Node root;

    public MyBwsImpl(Node root) {
        this.root = root;
    }

    @Override
    public <T> T parse(InputStream excel, WorkBookType type, Class<T> clazz) throws IOException {
        // TODO 自動生成されたメソッド・スタブ
        return null;
    }

    @Override
    public void format(OutputStream excel, WorkBookType type, Object data) throws IOException {
        ValueStack stack = new ValueStack();
        stack.push(data);

        Workbook book = type.create();
        WriteVisitor visitor = new WriteVisitor(book, stack);

        root.accept(visitor);

        book.write(excel);
    }

}
